//
//  ZYFirstViewController.m
//  MusicMV
//
//  Created by dllo on 16/3/25.
//  Copyright © 2016年 Eternity. All rights reserved.
//

#import "ZYFirstViewController.h"

@interface ZYFirstViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) UIImageView *imgeView;
@property (nonatomic, retain) UILabel *touLabel;
@property (nonatomic, retain) UILabel *timeLabel;
@property (nonatomic, retain) UIImageView *bigImage;
@property (nonatomic, retain) NSMutableArray *tempArr;
@end

@implementation ZYFirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self reatre];
    
    CGFloat picweight = self.view.frame.size.width;
    CGFloat picheight = [_model.height floatValue] / [_model.width floatValue] * picweight;

    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 64) style:(UITableViewStylePlain)];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
   
    _tableView.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:_tableView];
    
    [_tableView registerClass:[ZYFirstTableViewCell class] forCellReuseIdentifier:@"ZYReadTableViewCell"];

    
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, picheight + 55)];
    
    
    view.backgroundColor = [UIColor whiteColor];
    self.tableView.tableHeaderView = view;
    

    self.imgeView = [[UIImageView alloc] init];
    _imgeView.backgroundColor = [UIColor whiteColor];
    [_imgeView sd_setImageWithURL:[NSURL URLWithString:_model.avatar]];
    [view addSubview:_imgeView];
    [_imgeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(5);
        make.top.mas_equalTo(5);
        make.size.mas_equalTo(CGSizeMake(40, 40));
       
    }];
    
    self.touLabel = [[UILabel alloc] init];
    _touLabel.backgroundColor = [UIColor whiteColor];
    _touLabel.frame = CGRectMake(50, 5, 100, 40);
    _touLabel.text = _model.uname;
    [view addSubview:_touLabel];
    
    self.timeLabel = [[UILabel alloc] init];
    _timeLabel.backgroundColor = [UIColor whiteColor];
    [view addSubview:_timeLabel];
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(_imgeView.mas_top);
        make.size.mas_equalTo(CGSizeMake(70, 40));
        
    }];
    _timeLabel.text = [NSString stringWithFormat:@"🕒%@", _model.format_time];
    
    
    self.bigImage = [[UIImageView alloc] init];
    _bigImage.backgroundColor = [UIColor brownColor];
    _bigImage.frame = CGRectMake(0, 55, WIDTH, picheight);
    [_bigImage sd_setImageWithURL:[NSURL URLWithString:_model.photo]];

    [view addSubview:_bigImage];
    
    
}

#pragma mark - 点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ZYPLViewController *vc = [[ZYPLViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
    
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return _tempArr.count;
    
    
}
#pragma mark - cell高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 100;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ZYFirstTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZYReadTableViewCell"];
    cell.model = _tempArr[indexPath.row];
    return cell;
    
    
}

- (void)reatre {
    
    NSDictionary *dic = @{@"id":@1439135, @"uid":@386600};
    
    [APPTools POSTWithURL:@"http://api.enjoymusicapp.com/api/v1.1/song/detail.ema?sign=938d2e1159df7bb78e982a4c5d0f5e54&uid=386600&version=2.3.2&platform=ios" par:dic success:^(id responseObject) {
//        NSArray *arr = responseObject[@"data"][@"comments"];
//        self.tempArr = [ZYPLModel modelWithArray:arr];
        NSDictionary *dic = responseObject[@"data"];
        NSArray *arr = dic[@"comments"];
        self.tempArr = [ZYPLModel modelWithArray:arr];
        [_tableView reloadData];
    } filed:^(NSError *error) {
        
    }];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
